//
//  NSString+WHEncrypt.m
//  LvZhongMagicKey
//
//  Created by 邓伟浩 on 2017/12/15.
//  Copyright © 2017年 邓伟浩. All rights reserved.
//

#import "NSString+WHEncrypt.h"
#import<CommonCrypto/CommonDigest.h>

@implementation NSString (WHEncrypt)

+ (NSString *) sha1:(NSString *)input {
    
    NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding];
    
    uint8_t digest[CC_SHA1_DIGEST_LENGTH];
    
    CC_SHA1(data.bytes, (unsigned int)data.length, digest);
    
    NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
    
    for(int i=0; i<CC_SHA1_DIGEST_LENGTH; i++) {
        [output appendFormat:@"%02x", digest[i]];
    }
    
    return output;
}

@end
